package No1_100.No11_20.LongestCommonPrefix_14;

public class Solution {
    public static String longestCommonPrefix(String[] strs) {
    	if (strs.length == 0) {
			return "";
		}
    	String temp = strs[0];
    	if (temp.length() == 0) {
			return "";
		}
    	for (int i = 1; i < strs.length; i++) {
    		int min = temp.length()<strs[i].length()?temp.length():strs[i].length();
    		temp = temp.substring(0, min);
			for (int j = 0; j < min; j++) {
				if (temp.charAt(j)==strs[i].charAt(j)) {
					
				}
				else {
					temp = temp.substring(0, j);
					break;
				}
			}
		}
    	
    	return temp;
    }
    
    public static void main(String[] args) {
    	String[] aString = new String[2];
    	aString[0] = "aa";
    	aString[1] = "a";
    	System.out.println(longestCommonPrefix(aString));
		
	}
}
